package com.project.service.impl;

import com.project.bean.CarBean;
import com.project.bean.ManBean;
import com.project.mapper.IManMapper;
import com.project.service.IManService;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

/**
 * 公民业务接口实现类
 */
public class ManServiceImpl extends BaseService implements IManService {
    @Override
    public List<ManBean> findAll() {
        SqlSession session = this.getSession();
        IManMapper mapper = session.getMapper(IManMapper.class);
        List<ManBean> list = mapper.findAll();
        session.close();
        return list;
    }

    @Override
    public void addMan(ManBean man, List<CarBean> carList) {
        SqlSession session = this.getSession();
        IManMapper mapper = session.getMapper(IManMapper.class);
        mapper.addMan(man);
        mapper.addCarList(man.getId(),carList);
        session.commit();
        session.close();

    }

    @Override
    public void delCaseCade(int manId) {
        SqlSession session = this.getSession();
        IManMapper mapper = session.getMapper(IManMapper.class);
        mapper.delCaseCade(manId);
        session.commit();
        session.close();
    }

    @Override
    public void delSetNull(int manId) {
        SqlSession session = this.getSession();
        IManMapper mapper = session.getMapper(IManMapper.class);
        mapper.delSetNull(manId);
        session.commit();
        session.close();
    }

    @Override
    public ManBean findById(int manId) {
        SqlSession session = this.getSession();
        IManMapper mapper = session.getMapper(IManMapper.class);
        ManBean man = mapper.findById(manId);
        session.close();
        return man;
    }
}
